package com.tjetc.adminmanage;

import com.tjetc.domian.Maintenancerequest;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.MaintenanceService;
import com.tjetc.vo.Result;

import java.util.List;
import java.util.Scanner;

//  维修服务管理
public class MaintenanceManageView {
    private static Scanner scanner = new Scanner(System.in);
    private MaintenanceService maintenanceService = ClientProxy.getProxyInstance(MaintenanceService.class);
    public void start() {
        while (true) {
            System.out.println("维修服务管理菜单");
            System.out.println("1.查询维修服务");
            System.out.println("2.修改维修服务");
            System.out.println("0.返回上一级");
            switch (scanner.nextInt()) {
                case 1:
                    select();
                    break;
                case 2:
                    update();
                    break;
                case 0:
                    return;
                default:
                    System.out.println("输入有误，请重新输入");
                    break;
            }
        }

    }

    private void update() {
        System.out.println("修改维修服务");
        System.out.println("输入要修改的维修服务id");
        int requestid = scanner.nextInt();
        System.out.println("输入要修改的维修服务状态('待处理'、'处理中'、'已完成')");
        String status = scanner.next();
        Result result =maintenanceService.update(requestid,status);
        System.out.println(result.getMsg());
    }

    private void select() {
       List<Maintenancerequest> list = maintenanceService.selectAll();
       if (list.size() == 0){
           System.out.println("没有数据");
       }else{
           for (Maintenancerequest maintenancerequest : list){
               System.out.println("id"+maintenancerequest.getRequestid()+"resid"+maintenancerequest.getResidentid()+
                       "apartmentid"+maintenancerequest.getApartmentid()+"requestdate"+maintenancerequest.getRequestdate()+
                       "requesttime"+maintenancerequest.getRequesttime()+"description"+maintenancerequest.getDescription()+
                       "status"+maintenancerequest.getStatus()+"name" +maintenancerequest.getResident().getName());
           }
       }
    }
}
